﻿#ifndef _MAIN_TOP_AFFINE_H_
#define _MAIN_TOP_AFFINE_H_

#ifdef _WIN32
#ifdef __GNUC__
#define MtAffineCallType        __attribute__((stdcall))
#else
#define MtAffineCallType        __stdcall
#endif
#else
#define MtAffineCallType
#endif

#ifdef __cplusplus
extern "C" {
#endif

#pragma pack(4)
typedef struct _MtAffineMatrix {
  double        a, b, c, d, tx, ty;
} MtAffineMatrix;

typedef struct _MtAffineFPoint {
  double        x, y;
} MtAffineFPoint;
#pragma pack()

enum MtAffineRetCode {
  MT_AFFINE_RET_CODE_SUCC       = 0,
  MT_AFFINE_RET_CODE_ERR        = -1,
};

int MtAffineCallType
MtInvertAffineMatrix(MtAffineMatrix *d, const MtAffineMatrix *s);

int MtAffineCallType
MtMulMatrix2D(MtAffineMatrix *d, MtAffineMatrix *s0, const MtAffineMatrix *s1);

int MtAffineCallType
MtBuildOffsetMatrix2D(MtAffineMatrix *d, double tx, double ty);

int MtAffineCallType
MtBuildIdentityMatrix2D(MtAffineMatrix *d);

int MtAffineCallType
MtBuildMirrorVerMatrix2D(MtAffineMatrix *d, double ay);

int MtAffineCallType
MtBuildMirrorHorMatrix2D(MtAffineMatrix *d, double ax);

int MtAffineCallType
MtBuildRotationMatrix2D(MtAffineMatrix *d, const MtAffineFPoint *center,
                        double angle, double scale);

int MtAffineCallType
MtBuildScaleMatrix2D(MtAffineMatrix *d, const MtAffineFPoint *center,
                     double scalex, double scaley);

#ifdef __cplusplus
}
#endif

#endif
